package com.ningxia.water.controller.geographic;

import com.ningxia.water.entity.ZtVillageInfo;
import com.ningxia.water.reuslt.Result;
import com.ningxia.water.reuslt.ResultResponse;
import com.ningxia.water.service.IZtVillageInfoService;
import com.ningxia.water.utils.CommonUtils;
import com.ningxia.water.vo.out.ZonePidVo;
import com.ningxia.water.vo.out.ZoneVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author huangzhen
 * @create 2021-05-14 21:04
 */
@RestController
@RequestMapping("/village")
@Api(tags = {"地理信息-4-村庄管理"})
public class VillageController {

    @Autowired
    private IZtVillageInfoService villageInfoService;

    @GetMapping("/getvillageinfo")
    @ApiOperation("获取全部村庄地理信息")
    public Result getVillageInfo() {
        List<ZoneVo> list = villageInfoService.getVillageInfos();
        return ResultResponse.getSuccessResult(list);
    }

    @PostMapping("/insertvillageinfo")
    @ApiOperation(value = "新增村庄")
    public Result insertVillageInfo(@RequestBody ZtVillageInfo villageInfo) {
        return CommonUtils.commonResult(villageInfoService.save(villageInfo));
    }

    @PutMapping("/updatevillageinfo")
    @ApiOperation(value = "根据ID更新村庄")
    public Result updateVillageInfo(@RequestBody ZtVillageInfo villageInfo) {
        return CommonUtils.commonResult(villageInfoService.updateById(villageInfo));
    }


    @DeleteMapping("/deletevillageinfo")
    @ApiOperation(value = "根据id删除村庄")
    public Result deleteVillageInfo(@RequestParam("villageId") Integer villageId) {
        return CommonUtils.commonResult(villageInfoService.removeById(villageId));
    }

    @GetMapping("/getvillagerelationship")
    @ApiOperation(value = "获取村庄及其对应的乡镇id")
    public Result getVillageRelationship() {
        List<ZonePidVo> list = villageInfoService.getVillageRelationship();
        return ResultResponse.getSuccessResult(list);
    }
}
